package tests.listeners;

import java.util.EventListener;
import java.util.EventObject;


import zerdlib.events.DefaultListenable;
import zerdlib.events.GenericListener;
import zerdlib.events.WeakGenericListener;

import events.listenerWrappers.GenericListenerWrapper;

public class Test {
	static DefaultListenable evManager = new DefaultListenable();
	
	public static void main(String[] args) {
		GenericListener l1 = new TestListener(1);
		
		evManager.addListener(l1);
		evManager.addListener(l1);
		evManager.addListener(l1);
		evManager.addListener(l1);
		evManager.addListener(l1);
		notifyListeners(1);
		
		evManager.removeListener(l1);
		notifyListeners(2);
		evManager.removeListener(l1);
		notifyListeners(3);
		evManager.removeAllListener(l1);
		notifyListeners(4);
		
		evManager.addListener(new TestListener(2));
		WeakGenericListener.addWeakListener(evManager, new TestListener(3));
		GenericListener l4 = new TestListener(4);
		GenericListener l5 = new TestListener(5);
		evManager.addListener(l4);
		evManager.addListener(l4);
		evManager.addListener(l5);
		notifyListeners(5);
		
		System.gc();
		notifyListeners(6);
		
		l4 = null;
		System.gc();
		notifyListeners(7);
		
		evManager.addListener(l1);
		evManager.removeListener(l1);
		evManager.removeListener(l5);
		notifyListeners(8);
		
	}
	
	public static void notifyListeners(int i) {
		System.out.println("-----"+i+"-----");
		evManager.fireEvent(null);
		System.out.println();
	}

}
